from flask import Flask
# from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from flask_login import LoginManager
from flask_moment import Moment
from settings import Config
from common.db_util import db


# db = SQLAlchemy()
bootstrap = Bootstrap()
moment = Moment()
login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'main.login'


def create_app():
    app = Flask(import_name=__name__,
                static_folder="../static",
                template_folder="../templates")
    app.config.from_object(Config)
    Config.init_app(app)
    # CsrfProtect(app)

    db.init_app(app)
    bootstrap.init_app(app)
    moment.init_app(app)
    login_manager.init_app(app)
    # Avatar(app)

    from xshare.v_01.main.views import main
    from xshare.v_01.admin.user.views import user
    from xshare.v_01.admin.about.views import aboutus
    from xshare.v_01.admin.others.views import others
    from xshare.v_01.admin.index.views import index
    from xshare.v_01.admin.club.views import club
    app.register_blueprint(main)
    app.register_blueprint(user, url_prefix='/admin/user')
    app.register_blueprint(club, url_prefix='/admin/club')
    app.register_blueprint(others, url_prefix='/admin/others')
    app.register_blueprint(aboutus, url_prefix='/admin/aboutus')
    app.register_blueprint(index, url_prefix='/admin')

    return app
